package com.woniu.custom.controller;

import com.woniu.common.utils.ResponseData;
import com.woniu.custom.pojo.Addr;
import com.woniu.custom.service.AddrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * packageName com.woniu.custom.controller
 *
 * @author zxyang3636
 * @version JDK 8
 * @className AddrController
 * @date 2024/8/8
 * @description TODO
 */
@RestController
public class AddrController {

    @Autowired
    private AddrService addrService;

    @GetMapping("/selUserAddrById")
    public Addr selUserAddrById(@RequestParam("addressId") String addressId) {
        return addrService.lambdaQuery().eq(Addr::getId, addressId).one();
    }

    @GetMapping("/queryAddrByUserId")
    public ResponseData<?> queryAddrByUserId() {
        return addrService.queryAddrByUserId();
    }

    @GetMapping("/queryAddrById")
    ResponseData<Addr> queryAddrById(@RequestParam("addressId") String addressId){
        Addr addr = addrService.getById(addressId);
        return new ResponseData<>().success(addr);
    }
    @PostMapping("/selectAddr")
    public Addr selectAddr(@RequestBody String addressId){
        return addrService.selectAddr(addressId);
    }

    @PostMapping("/addAddr")
    public ResponseData<?> addAddr(@RequestBody Addr newAddr){
        return addrService.addAddr(newAddr);
    }
}
